<template>
  <div class="songdetail">
    <div class="song-top">
      <div class="img">
        <img :src="playlist.coverImgUrl" alt="" />
      </div>
      <div class="song-title">
        <div class="title">{{ playlist.name }}</div>
        <div class="title-conent">
          <div class="song-names" v-if="playlist.creator!=undefined">{{ playlist.creator.nickname }}</div>
          <div class="label">标签：{{ playlist.tags.join()}}</div>
          <div class="counts">播放量： {{ playlist.playCount | handleNum }}万</div>
          <div class="collect">收藏量 ： {{ playlist.subscribedCount }}</div>
          <div class="keys">
            <div class="play">播放全部</div>
            <div class="collect-play" @click="handleColl(playlist)">收藏</div>
            <div class="comment-play">评论</div>
            <div class="more-play">更多</div>
          </div>
        </div>
      </div>
    </div>
    <div class="song-conent">
      <div class="song-list">
        <div class="list-top">
          <div class="name">歌曲</div>
          <div class="song">歌手</div>
          <div class="album">专辑</div>
          <div class="time">时长</div>
        </div>
        <div
          class="song-item"
          v-for="(item, index) of songdetail"
          :key="item.id"
        >
          <span>{{ index + 1 }}</span>
          <div class="song-name">
            <a href="##" @click="handlePlay(item.id)">{{ item.name }}</a>
            <div class="box">
              <span
                class="iconfont icon-jiahao"
                @click="handlePaly(item)"
              ></span>
              <a href="##">
                <span
                  class="iconfont icon-xiai"
                  @click="handleCollect(item)"
                ></span>
              </a>
            </div>
          </div>
          <div class="song">{{ item.ar[0].name }}</div>
          <div class="album">{{ item.name }}</div>
          <div class="time">{{ item.dt | handleTime }}</div>
        </div>
      </div>
      <div class="brief">
        <div class="brief-title">简介</div>
        <div class="brief-conent">
          {{ playlist.description }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      playlist: [],
      songdetail: [],
    };
  },
  mounted() {
    var { id } = this.$route.query;
    this.$http.get(`/playlist/detail?id=${id}`).then((res) => {
      this.playlist = res.data.playlist
      this.songdetail = res.data.playlist.tracks;
    });
  },
  methods: {
    handlePlay(val) {
      this.$router.push(`play?id=${val}`);
    },
    handleColl(val) {
      this.$http
        .post("http://127.0.0.1:7001/collection", { val })
        .then((res) => {
          console.log(res);
        });
    },
    handlePaly(val) {
      console.log(val);
      this.$https.post("/playmusic", { val }).then((res) => {
        if (res.data.code == 400) {
          this.$message({
            showClose: true,
            message: "已经添加，请不要重复添加",
          });
        }
        this.$bus.$emit("shuaxin");
      });
    },
    handleCollect(val) {
      console.log(val);
      this.$https.post("/musiccollect", { val }).then((res) => {
        console.log(res);
      });
    },
  },
};
</script>

<style scoped>
.songdetail {
  width: 1200px;
  margin: 0 auto;
  margin-top: 30px;
}

.img img {
  width: 250px;
  height: 250px;
}
.song-top {
  display: flex;
}
.song-title {
  padding: 20px 30px;
}
.title {
  font-size: 18px;
}
.title-conent {
  margin-top: 30px;
}
.title-conent > div {
  margin-bottom: 20px;
}
.keys {
  margin-top: 20px;
  display: flex;
}
.keys > div {
  margin-right: 30px;
}
.song-names {
  color: aquamarine;
}
.play {
  border: 1px solid #c9c9c9;
  border-radius: 5px;
  padding: 10px 20px;
  background: #abc4ff;
  color: #fff;
}
.collect-play {
  border: 1px solid #c9c9c9;
  border-radius: 5px;
  padding: 10px 20px;
}
.comment-play {
  border: 1px solid #c9c9c9;
  border-radius: 5px;
  padding: 10px 20px;
}
.more-play {
  border: 1px solid #c9c9c9;
  border-radius: 5px;
  padding: 10px 20px;
}
.song-conent {
  display: flex;
  margin-top: 50px;
}
.song-list {
  width: 900px;
  background-color: #fbfbfd;
}
.list-top {
  display: flex;
  padding: 20px 0;
}
.song-item {
  display: flex;
  line-height: 50px;
}
.song-item span {
  width: 60px;
  font-size: 14px;
  color: #999;
  text-align: center;
}
.song-item:nth-child(2n) {
  background-color: #f7f7f7;
}
.name {
  margin-left: 60px;
  width: 300px;
}
.song {
  font-size: 14px;
  color: #333;
  width: 180px;
}
.album {
  font-size: 14px;
  color: #333;
  width: 250px;
}
.time {
  font-size: 14px;
  color: #999;
  width: 150px;
}
.song-name {
  display: flex;
  justify-content: space-between;
  color: #333;
  font-size: 14px;
  width: 300px;
  right: 0;
  top: 0;
}
.song-name a:hover {
  color: #abc4ff;
}
.brief {
  margin-left: 30px;
  font-size: 14px;
  line-height: 18px;
  width: 300px;
}
.box {
  width: 70px;
  display: none;
}
.song-item:hover .box {
  display: block;
}
.box span {
  margin-left: 10px;
}
.box .icon-xiai:hover {
  color: red;
}
.box .icon-jiahao:hover{
  color: cyan;
}
</style>